package com.sy.simpleegg.mvp.presenter

import androidx.lifecycle.LifecycleCoroutineScope
import com.sy.simpleegg.base.BasePresenter
import com.sy.simpleegg.bean.ClearDataBean
import com.sy.simpleegg.mvp.contract.FastManageContract
import com.sy.simpleegg.mvp.model.FastManageModel
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext

class FastManagePresenter(private val lifecycleCoroutineScope: LifecycleCoroutineScope): BasePresenter<FastManageContract.Model, FastManageContract.View>(), FastManageContract.Presenter {

    override fun createModel(): FastManageContract.Model = FastManageModel()
    override fun saveCoins(coins: Long) {
        lifecycleCoroutineScope.launch {
            withContext(Dispatchers.IO){
                mModel?.saveCoins(coins)
            }
            mView?.saveCoinsFinish()
        }
    }

    override fun getClearData() {
        lifecycleCoroutineScope.launch {
            var clearDatas: MutableList<ClearDataBean>? = mutableListOf()
            withContext(Dispatchers.IO){
                clearDatas = mModel?.getClearData()
            }
            mView?.showClearData(clearDatas)
        }
    }


}